﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class PR_ScoreSub : System.Web.UI.Page
    {
        private SsMng ssMng = new SsMng();
        private IJobSiteBLL jsBLL = new JobSiteBLL();
        private BudgetManagementTestBLL bgBLL = new BudgetManagementTestBLL();
        private RadComboBox cmbEmployeeType, cmbYear;
        int EmpSeq;
        protected void Page_Load(object sender, EventArgs e)
        {
            cmbYear = (RadComboBox)cbYear.FindControl("cbYear");
            cmbEmployeeType = (RadComboBox)cbEmployeeType.FindControl("cbEmployeeType");

            if (!IsPostBack)
            {
                EmpSeq = ssMng.EmpSeqI;
                cbEmployeeType.ListEmployeeTypeComboBox();
                cbYear.ListYear();
                cmbYear.SelectedValue = Convert.ToString(Int32.Parse(DateTime.Today.Year.ToString()) + 543);

                ListJobSite();
                cmbJobSite.SelectedValue = bgBLL.GetJobSiteSeq(this.EmpSeq).ToString();
                GetDepartName();
            }            
        }
        private void GetDepartName()
        {
            BudgetManagementTestBLL obj = new BudgetManagementTestBLL();
            lblDepName.Text = obj.GetDepartName(this.EmpSeq);
        }
        public void ListEmployeeTypeComboBox()
        {
            //IList<EmployeeTypeInfo> InfoList = BLL.ListEmployeeTypes();

            //cbEmployeeType.DataSource = InfoList;
            //cbEmployeeType.DataBind();
        }

        private void bindYearCombo()
        {
            int curYear, min, max;

            curYear = int.Parse(DateTime.Today.Year.ToString());
            curYear += 543;
            min = curYear - 10;
            max = curYear + 10;
            
            cbYear.ListYear(min, max);
        }
        protected void ListJobSite()
        {
            JobSiteTypeInfo Info = new JobSiteTypeInfo();
            IList<JobSiteInfo> InfoList = jsBLL.ListJobSiteByTypes(SystemInfo._JobsiteInternal);

            cmbJobSite.DataSource = InfoList;
            cmbJobSite.DataBind();
        }
        private void LoadDataGrid()
        {
            try
            {
                DataTable dt;
                ScoreSubBLL obj = new ScoreSubBLL();
                dt = obj.select(Int32.Parse(Session["PRMID"].ToString())
                    , cmbJobSite.SelectedValue.Length > 0 ? Int32.Parse(cmbJobSite.SelectedValue) : (int?)null
                    , (double?)null); 
             
                RadGrid2.DataSource = dt;
                RadGrid2.DataBind();
            }
            catch (Exception ex)
            {

            }
        }

        protected void RadGrid2_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                int seq = Convert.ToInt32((e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["sub_sco_level_seq"]);
                ScoreSubBLL obj = new ScoreSubBLL();
                obj.Delete(seq, ssMng.EmpSeqI);
            }
            Session["JSID"] = cmbJobSite.SelectedValue;
            Session["PRMID"] = bgBLL.GetPrmPromotionSeq(Int32.Parse(cmbEmployeeType.SelectedValue)
                , Int32.Parse(cmbYear.SelectedValue)
                , Int32.Parse(radPeriod.SelectedValue));
            LoadDataGrid();
        }

        protected void cmdSearch_Click(object sender, EventArgs e)
        {
            Session["JSID"] = cmbJobSite.SelectedValue;
            Session["PRMID"] = bgBLL.GetPrmPromotionSeq(Int32.Parse(cmbEmployeeType.SelectedValue)
                , Int32.Parse(cmbYear.SelectedValue)
                , Int32.Parse(radPeriod.SelectedValue));
            LoadDataGrid();
        }

    }
}
